package com.origin.niuke.bit_operation;

/**
 * NC227 只出现一次的数字(二)
 * 算法：位运算
 *
 * @author yezh
 * @date 2022/12/3 21:52
 */
public class NC227 {

    public int singleNumber (int[] nums) {
        // write code here
        int ans = 0;
        int[] bits = new int[32];
        for (int num : nums) for (int i = 0; i < 32; i++) bits[i] += num >> i & 1;
        for (int i = 0; i < 32; i++) if (bits[i] % 3 == 1) ans |= (1 << i);
        return ans;
    }

}
